/*
 * Copyright 2012 SerGenis. All rights reserved.
 */
package com.sergenis.form;

import java.util.ArrayList;
import java.util.List;

import com.sergenis.beans.AbstractBean;

/**
 * @author SerGenis
 * @deprecated 
 */
public class FormCollection<E>
    extends AbstractBean
    implements IDialogFormResultado {

    protected E active;
    public static final String PROP_ACTIVO = "active";

    public E getActive() {
	return active;
    }

    public void setActive(E active) {
	E oldActivo = this.active;
	this.active = active;
	firePropertyChange(PROP_ACTIVO, oldActivo, active);
    }
    protected List<E> elements = new ArrayList();
    public static final String PROP_ELEMENTS = "elements";

    public List getElements() {
	return elements;
    }

    public void setElements(List elements) {
	List oldElements = this.elements;
	this.elements = elements;
	firePropertyChange(PROP_ELEMENTS, oldElements, elements);
    }

    public void add(E element) {
	E[] aElements = (E[]) elements.toArray();
	List<E> newElements = new java.util.ArrayList<E>(java.util.Arrays.asList(
	    aElements));
	newElements.add(element);
	setElements(newElements);
    }

    public E get(int index) {
	return elements.get(index);
    }

    public int indexOf(Object o) {
	return elements.indexOf(o);
    }

    public E set(int index, E element) {
	E[] aElements = (E[]) elements.toArray();
	List<E> newElements = new java.util.ArrayList<E>(java.util.Arrays.asList(
	    aElements));
	E oldElement = newElements.set(index, element);
	setElements(newElements);
	return oldElement;
    }

    public boolean remove(E element) {
	int index = elements.indexOf(element);
	return (!elements.contains(remove(index)));
    }

    public E remove(int index) {
	E[] aElements = (E[]) elements.toArray();
	List<E> newElements = new java.util.ArrayList<E>(java.util.Arrays.asList(
	    aElements));
	E element = newElements.remove(index);
	setElements(newElements);
	return element;
    }

    public int size() {
	return elements.size();
    }

    public boolean isEmpty() {
	return elements.isEmpty();
    }

    public void resetElements() {
	this.elements.clear();
	this.resultado = CANCELAR;
    }
    protected int resultado = CANCELAR;

    public void setResultado(int estado) {
	this.resultado = estado;
    }

    public int getResultado() {
	return resultado;
    }
}
